package top.drinyeit.weilong.presenter;

import android.content.Intent;

import java.util.Map;

import top.drinyeit.weilong.activity.NickNameActivity;
import top.drinyeit.weilong.app.Constant;
import top.drinyeit.weilong.retrofit.HttpResponse;
import top.drinyeit.weilong.retrofit.RetrofitMethod;
import top.drinyeit.weilong.retrofit.subscriber.CommonSubscriber;
import top.drinyeit.weilong.retrofit.subscriber.SubscriberListener;
import top.drinyeit.weilong.util.SPUtil;

import static top.drinyeit.weilong.app.Constant.COMMON_SUCCESS;

/**
 * Created by bigHead on 2018/1/3.
 */

public class NickNamePresenter {
    private NickNameActivity activity;

    public NickNamePresenter(NickNameActivity activity) {
        this.activity = activity;
    }

    //编辑昵称
    public void editInf(Map<String,Object> map) {
        activity.showLoading();
        CommonSubscriber<HttpResponse<String>> subscriber = new CommonSubscriber<>(new SubscriberListener<HttpResponse<String>>() {
            @Override
            public void onError(String e, int code) {
                activity.dismissLoading();
                activity.showToastMsg("错误，请重新操作！");
            }

            @Override
            public void onNext(HttpResponse<String> o) {
                activity.dismissLoading();
                activity.showToastMsg(o.getMessage());
                if (o.getCode() == COMMON_SUCCESS) {
                    Intent intent = new Intent();
                    intent.putExtra("nick_name",activity.nick_name.getText().toString());
                    activity.setResult(10,intent);
                    activity.finish();
                }

            }
        });
        RetrofitMethod.getInstance().editInf(subscriber, map);
    }
}
